package com.shamyang.java8.c01;

import java.util.Objects;

/**
 * 苹果
 */
public class Apple implements Comparable<Apple>{

    /**
     * 颜色
     */
    private String color;

    /**
     * 重量
     */
    private Integer weight;

    /**
     * 等级
     */
    private Integer level;

    public Apple() {
    }

    public Apple(String color, Integer weight) {
        this.color = color;
        this.weight = weight;
    }

    public Apple(String color, Integer weight, Integer level) {
        this.color = color;
        this.weight = weight;
        this.level = level;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public Integer getWeight() {
        return weight;
    }

    public void setWeight(Integer weight) {
        this.weight = weight;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    @Override
    public String toString() {
        return "Apple{" +
                "color='" + color + '\'' +
                ", weight=" + weight +
                ", level=" + level +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Apple apple = (Apple) o;
        return Objects.equals(color, apple.color) &&
                Objects.equals(weight, apple.weight);
    }

    @Override
    public int hashCode() {
        return Objects.hash(color, weight);
    }

    @Override
    public int compareTo(Apple apple) {
        return apple.getWeight().compareTo(getWeight());
    }
}
